package com.labichaoka.chaoka.ui.quote;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.labichaoka.chaoka.R;
import com.labichaoka.chaoka.base.BaseActivity;
import com.labichaoka.chaoka.entity.LimitStatusResponse;
import com.labichaoka.chaoka.ui.baseinfo.edu.EducationImgUploadActivity;
import com.labichaoka.chaoka.ui.fetch.FetchMoneyActivity;
import com.labichaoka.chaoka.utils.DetectionUtil;
import com.labichaoka.chaoka.utils.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

/*
* 激活专属额度
* */

public class QuoteActivity extends BaseActivity implements QuoteView{

    @BindView(R.id.total)
    TextView total;
    @BindView(R.id.quote_txt)
    TextView quoteTxt;
    @BindView(R.id.btn_txt)
    TextView btnTxt;
    @BindView(R.id.status_txt)
    TextView statusTxt;
    @BindView(R.id.fetch)
    TextView fetch;
    @BindView(R.id.txt_warning)
    TextView txt_warning;




    private QuotePresenter presenter;

    @Override
    protected int initLayoutId() {
        return R.layout.activity_quote;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        presenter=new QuotePresenterImpl(new QuoteInteractorImpl(),this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.calculate();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @OnClick({R.id.btn_txt,R.id.fetch})
    public void click(View v){
        switch (v.getId()){
            case R.id.btn_txt:
                gotoActivity(mContext,EducationImgUploadActivity.class,null);
                break;
            case R.id.fetch:
                //提现
                gotoActivity(mContext, FetchMoneyActivity.class,null);
                break;
        }

    }

    @Override
    public void showProgress() {
        showLoadingProgress();
    }

    @Override
    public void hideProgress() {
        hideLoadingProgress();
    }

    @Override
    public void showMessage(String str) {
        ToastUtils.show(str);
    }

    @Override
    public void setData(LimitStatusResponse response) {
        String flag=getIntent().getStringExtra("flag");
        if (TextUtils.isEmpty(flag)){
            quoteTxt.setText("我的专属额度");
        }else{
            quoteTxt.setText("恭喜您，成功获得专属额度!");
        }
        String totalValue=response.getData().getTotalQuota();
        if (TextUtils.isEmpty(totalValue)){
            ToastUtils.show("获取数据错误!");
            return;
        }
        total.setText(DetectionUtil.addComma(totalValue));

        String status=response.getData().getReviewStatus();
        if (!TextUtils.isEmpty(status)){
            switch (status){
                case "0":
                    statusTxt.setVisibility(View.GONE);
                    btnTxt.setVisibility(View.VISIBLE);
                    fetch.setVisibility(View.GONE);
                    break;
                case "1":
                    statusTxt.setVisibility(View.VISIBLE);
                    btnTxt.setVisibility(View.GONE);
                    statusTxt.setText("审核通过");
                    fetch.setVisibility(View.VISIBLE);
                    txt_warning.setVisibility(View.GONE);
                    break;
                case "2":
                case "3":
                    statusTxt.setVisibility(View.VISIBLE);
                    btnTxt.setVisibility(View.GONE);
                    statusTxt.setText("审核中");
                    fetch.setVisibility(View.GONE);
                    break;
                default:
                    statusTxt.setVisibility(View.VISIBLE);
                    btnTxt.setVisibility(View.GONE);
                    statusTxt.setText("审核未通过");
                    fetch.setVisibility(View.GONE);
                    break;
            }
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onDestroy();
    }
}
